﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace Cassinipp.WebServer
{
    public static class ExtendedMimeTypes
    {
        private static Dictionary<string, string> MimeTypes = new Dictionary<string, string>()
        {
            // XBAP
            { ".manifest", "application/manifest" },
            { ".xbap", "application/x-ms-xbap" },
            { ".deploy", "application/octet-stream" },
            { ".application", "application/x-ms-application" },
            { ".xps", "application/vnd.ms-xpsdocument" },
            { ".xaml", "application/xaml+xml" },

            // Missing Image formats
            { ".png", "image/png" },
            { ".svg", "image/svg+xml" }
        };

        public static string GetForPath(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            string extension = Path.GetExtension(path);

            return GetForExtension(extension);
        }

        public static string GetForExtension(string extension)
        {
            if (extension == null)
            {
                throw new ArgumentNullException("extension");
            }

            string lookupExtension = extension.ToLowerInvariant();

            if (MimeTypes.ContainsKey(lookupExtension))
            {
                return MimeTypes[lookupExtension];
            }

            return null;
        }
    }
}
